package com.utils.code;

import com.utils.code.VerifyCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * 创建作者 ：MySunshine
 * 创建时间 2022/10/6 19:56
 * 项目名称 day03_forward
 */
@WebServlet("/showCode")
public class ServletShowCode extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        VerifyCode vc = new VerifyCode();
        BufferedImage image = vc.createImage();
        String code = vc.getText();
        HttpSession session = req.getSession();
        session.setAttribute("code",code);
        vc.output(image,resp.getOutputStream());
    }
}